package com.fh.rabbit;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class DeadExchange {
    //创建普通交换机
    @Bean
    public DirectExchange orderDirectExchange(){
        return new DirectExchange("orderDirect");
    }

    //创建延迟交换机
    @Bean
    public DirectExchange orderTtlDirect(){
        return new DirectExchange("orderTtlDirect");
    }
    //创建队列
    @Bean
    public Queue orderQueue(){
        return new Queue("orderQueue");
    }
    /*
    给交换机设置key
    */
    @Bean
    public Queue orderTtlQueue(){
        Map<String, Object> arguments=new HashMap<>();
        arguments.put("x-dead-letter-exchange","orderDirect");
        arguments.put("x-dead-letter-routing-key","orderDirectRoutingKey");
        return new Queue("orderTtlQueue",true,false,false,arguments);
    }

    /**
     * 将订单交换机和队列绑定
     * @return
     */
    @Bean
    public Binding orderDirectBindingDemo(){
        return BindingBuilder.bind(orderQueue()).to(orderDirectExchange()).with("orderDirectRoutingKey");
    }

    /**
     * 将订单延迟交换机和队列绑定
     * @return
     */
    @Bean
    public Binding orderTtlDirectBindingDemo(){
        return BindingBuilder.bind(orderTtlQueue()).to(orderTtlDirect()).with("orderTtlDirectRoutingKey");
    }



}
